package com.example.kafka.service;

import com.example.kafka.constant.KafkaConstant;

import java.util.Properties;

/**
 * @application:
 * @author: LiYuhang
 * @Date: 2021/6/26 14:35
 * @version: 0.1
 * @Description :
 * @Modified By:
 */
public interface Consumer {
    /**
     * CONSUMER接口
     *
     * @param servers
     * @param autoCommit
     * @param groupID
     * @return
     */
    static Properties creatConfig(String servers,String groupID,boolean autoCommit) {
        Properties config = new Properties();
        config.put("bootstrap.servers",servers);
        config.put("group.id",groupID);
        config.put("enable.auto.commit",autoCommit);
        config.put("auto.commit.interval.ms","1000");
        config.put("auto.offset.reset","earliest");
        config.put("session.timeout.ms",30000);
        config.put("key.deserializer",KafkaConstant.DESERIALIZER);
        config.put("value.deserializer",KafkaConstant.DESERIALIZER);
        return config;
    }

    /**
     * 默认配置
     * @param groupId
     * @return
     */
    static Properties getDefaultConfig(String groupId) {
        return creatConfig("47.100.82.240:9092",groupId,true);
    }

    /**
     * 默认配置
     * @param groupId
     * @param autoCommit
     * @return
     */
    static Properties getDefaultConfig(String groupId,boolean autoCommit) {
        return creatConfig("47.100.82.240:9092",groupId,autoCommit);
    }


}
